Return * for n number of times


Posted by Christy on 2022-04-19

Description: Write a function that accepts a number n and returns * for n number of times

function star(n) {

}

console.log(star(3)); // ***
function star(n) {
  let result = "";
  for (let i = 1; i <= n; i++) {
    result += "*";
  }
  return result;
}

console.log(star(3));

Be careful about the way of ouput, if it's print -> console.log; if it's return -> return










Related Posts

[TensorFlow Certification Day3] TensorFlow的人工智能, 機器學習和深度學習簡介 Week2/3

[TensorFlow Certification Day3] TensorFlow的人工智能, 機器學習和深度學習簡介 Week2/3

淺談 JavaScript 頭號難題 this:絕對不完整,但保證好懂

淺談 JavaScript 頭號難題 this:絕對不完整,但保證好懂

資結、Introduction to Algorithm Design

資結、Introduction to Algorithm Design


Comments